package com.wyh.aop.aspect;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

//表明这是一个切面类
@Aspect
//如果没有这个注解，切面类是不会发挥作用的，因为不会注入
@Component
//决定切面类的优先级，如果没有序号，就会根据包或者类的名称的字典序决定
@Order
public class AspectDemo2 {
    @Pointcut("execution(* com.wyh.aop.controller.*.*(..))")
    public void p(){}

    @Before("p()")
    public void doBefore(){
        System.out.println("------------------------doBefore......-------------------");
        ServletRequestAttributes request = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        System.out.println(request.getRequest());
        System.out.println("2");
    }
}
